/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lifxue.jqda.data;

import java.awt.Point;
import java.io.File;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.lifxue.jqda.util.GlobalConstant;
import org.lifxue.jqda.util.GlobalVar;

/**
 *
 * @author lifxue
 */
public class DataUtil {

    private static Log logger = LogFactory.getLog(DataUtil.class);

    public static Point getPointFromHashMap() {
        Point point = new Point(0, 0);
        Iterator i = GlobalVar.CONFIG.entrySet().iterator();
        while (i.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) i.next();
            String key = (String) entry.getKey(); //返回与此项对应的键
            String value = (String) entry.getValue(); //返回与此项对应的值
            if (key.equals(GlobalConstant.CONFIG_FILE_X)) {
                point.x = Integer.parseInt(value);
            }
            if (key.equals(GlobalConstant.CONFIG_FILE_Y)) {
                point.y = Integer.parseInt(value);
            }
        }
        return point;
    }

    public static void updateConfigFile() {
        try {
            File file = new File(GlobalVar.USER_HOME + GlobalVar.FILE_PATH_DELIMITER + GlobalConstant.DEFAULT_CONFIG_DIR + GlobalVar.FILE_PATH_DELIMITER + GlobalConstant.CONFIG_FILE);
            if (file.isFile() && file.exists()) {
                file.delete();
                new XmlData().writeConfigXml(file, GlobalVar.CONFIG, GlobalVar.HOTKEY);
            }
        } catch (Exception ex) {
            logger.debug(ex);
        }
    }

    public static void updateAppsFile() {
        try {
            File file = new File(GlobalVar.USER_HOME + GlobalVar.FILE_PATH_DELIMITER + GlobalConstant.DEFAULT_CONFIG_DIR + GlobalVar.FILE_PATH_DELIMITER + GlobalConstant.APPS_FILE);
            if (file.isFile() && file.exists()) {
                file.delete();
                new XmlData().writeAppsXml(file, GlobalVar.APPLICATIONS, GlobalVar.SCAN_DIR);
            }
        } catch (Exception ex) {
            logger.debug(ex);
        }

    }
}
